package com.haixiaoke.saas.enterprise.messageCenter.controller;

import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.messageCenter.domain.PushRecord;
import com.haixiaoke.saas.messageCenter.service.IPushRecordService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 推送记录信息Controller
 *
 * @author xiaolong
 * @date 2024-11-20
 */
@RestController
@RequestMapping("/enterprise/messageCenter/pushRecord")
public class EnterprisePushRecordController extends BaseController {
    @Autowired
    private IPushRecordService pushRecordService;

    /**
     * 查询推送记录信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:pushRecord:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(PushRecord pushRecord) {
        startPage();
        pushRecord.setTenantId(TenantContext.getTenantId());
        List<PushRecord> list = pushRecordService.selectPushRecordList(pushRecord);
        return getDataTable(list);
    }


    /**
     * 获取推送记录信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:pushRecord:query')")
    @GetMapping(value = "/{pushRecordId}")
    @TenantScope
    public AjaxResult getInfo(@PathVariable("pushRecordId") Long pushRecordId) {
        return success(pushRecordService.getInfo(pushRecordId));
    }

    /**
     * 统计消息未读数量
     */
    @PreAuthorize("@ss.hasPermi('enterprise:pushRecord:statistics')")
    @GetMapping(value = "/statistics")
    @TenantScope
    public AjaxResult getStatistics() {
        return success(pushRecordService.getStatisticsByTenantId(TenantContext.getTenantId()));
    }
}
